package insight.miescor.opp.domain;

import java.util.List;

import org.sormula.Database;
import org.sormula.SormulaException;
import org.sormula.Table;
import org.sormula.annotation.Where;
import org.sormula.annotation.WhereField;
import org.sormula.annotation.Wheres;


@Wheres({
    @Where(name="step", whereFields=@WhereField(name="step", comparisonOperator="=")) 
})


public class WorkflowRole {
	private int id;
	private int step;
	private String role;
	private String description;
	
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public int getStep() {
		return step;
	}
	public void setStep(int step) {
		this.step = step;
	}
	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}
	
	public static List<WorkflowRole> getRolesByStep(Database database, int step)throws SormulaException{
		Table<WorkflowRole> roleTable = database.getTable(WorkflowRole.class);
		System.out.println("Role: "+roleTable.toString());
		List<WorkflowRole> roleList = roleTable.selectAllWhere("step", step);
		System.out.println("Size: "+roleList.size());
		return roleList;
	}
	
	public static String getRolesDescription(Database database, String roleName)throws SormulaException{
		Table<WorkflowRole> roleTable = database.getTable(WorkflowRole.class);
		List<WorkflowRole> roleList = roleTable.selectAllCustom("where role=?", roleName);
		if(roleList.size()==0){
			return "";
		}else
			return roleList.get(0).getDescription();
	}
	@Override
	public String toString() {
		return "WorkflowRole [id=" + id + ", step=" + step + ", role=" + role
				+ ", description=" + description + "]";
	}

	
}
